/**
 * @file
 * @description  公共库
 */
import { MessageBox } from "element-ui";

/**
 * @method
 * @description
 * @param {String} message   提示的内容
 * @param {String} title   提示的标题
 */
export const confirm = (message, title = "提示") => {
    return new Promise((resolve, reject) => {
        MessageBox.confirm(message, title, {
            callback(action) {
                switch (action) {
                    case "confirm":
                        resolve();
                        break;
                    case "cancel":
                        reject();
                        break;
                }
            }
        });
    });
}

export const deepClone = (source) => {
    const newObj = Array.isArray(source) ? [] : {}; //新对象  
    /**
     * @description 拷贝方法
     * @param {Object} dest  目标对象
     * @param {Object} sour  
     */
    const clone = (dest, sour) => {
        for (const key in sour) {
            if (Object.hasOwnProperty.call(sour, key)) {
                const item = sour[key];
                if (item instanceof RegExp) { dest[key] = new RegExp(item); } else if (item instanceof Date) { dest[key] = new Date(item); } else if (item instanceof Object) { clone((dest[key] = Array.isArray(item) ? [] : {}), item); } else { dest[key] = item; }
            }
        }
    }
    clone(newObj, source);
    return newObj
}